define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template', 'cookie'], function ($, undefined, Backend, Table, Form, Template, undefined) {
    $.cookie.prototype.defaults = { path: Config.moduleurl };
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'depot/supplier/index',
                    add_url: 'depot/supplier/add',
                    edit_url: 'depot/supplier/edit',
                    del_url: 'depot/supplier/del',
                    table: 'depot_supplier',
                },
                pageSize: 20, //调整分页大小为20
                pageList: [10, 25, 50, 100, 'All'], //增加一个100的分页大小
                
            });

            var table = $("#table");
   
            var tableOptions = {
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                sortOrder: 'desc',
                search: false,
                columns: [
                    [
                        { checkbox: true },
                        { field: 'id', title: __('Id'), sortable: true },
                        { field: 'name', title: __('Name'), operate: 'LIKE' },
                        {field: 'mobile', title: __('Mobile'), operate: 'LIKE' },
                        { field: 'region.province', title: __('Province'), operate: 'LIKE' },
                        { field: 'region.city', title: __('City'), operate: 'LIKE' },
                        { field: 'region.district', title: __('District'), operate: 'LIKE' },
                        { field: 'address', title: __('Address'), operate: 'LIKE' },
                        { field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            };
            // 初始化表格
            table.bootstrapTable(tableOptions);

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
            setTimeout(function () {
                $("#c-type").trigger("change");
            }, 100);
        },
        edit: function () {
            Controller.api.bindevent();
        },
        del: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
})